package com.camerareader.mvp.setting_page;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.Switch;
import android.widget.TextView;

import com.camerareader.R;
import com.camerareader.mvp.BaseActivity;
import com.fileoperation.BaseSetting;
import com.fileoperation.CommonUtils;
import com.fileoperation.FileTools;
import com.fileoperation.model.LogOutEvent;
import com.fileoperation.user.UserInfo;

import org.greenrobot.eventbus.EventBus;
import org.w3c.dom.Text;

import java.io.File;

public class SettingActivity extends BaseActivity {

    private final String TAG = "SettingActivity";

    private TextView userName;
    private Switch autoUpload;
    private TextView savePath;
    private TextView deskInfo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        initView();
    }

    @Override
    protected void onServiceConnected() {

    }

    @Override
    protected void onServiceDisconnected() {

    }

    private void initView() {
        findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });

        userName = (TextView) findViewById(R.id.username);
        userName.setText(UserInfo.getInstance().getUsername());
        autoUpload = (Switch) findViewById(R.id.auto_upload);
        autoUpload.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                BaseSetting.getInstance().setAutoMode(isChecked);
                Log.w(TAG, "is auto mode  ==  " + BaseSetting.getInstance().isAutoMode());
            }
        });
        autoUpload.setChecked(BaseSetting.getInstance().isAutoMode());


        savePath = (TextView) findViewById(R.id.save_path);
        savePath.setText(FileTools.DIR_PATH);
        deskInfo = findViewById(R.id.deskInfo);

        File file = new File(FileTools.DIR_PATH);
        String deskInfoStr = "已使用："+ FileTools.formatSize(file.getTotalSpace() - file.getUsableSpace()) + "  可使用："+FileTools.formatSize(file.getUsableSpace());
        deskInfo.setText(deskInfoStr);
    }


    public static void navigateSettingPage(Activity activity){
        Intent intent = new Intent(activity, SettingActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        activity.startActivity(intent);
    }


    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish();
    }
}
